package com.huabo.schedule;

import com.huabo.utils.FastJsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * 保证多个任务间不会同时执行
 * Created by Jackie Liu on 2017/8/2.
 */
@DisallowConcurrentExecution
public class DisallowConcurrentJobFactory extends AbstractJobFactory implements Job {

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        String scheduleJob = (String) jobExecutionContext.getMergedJobDataMap().get(ScheduleManager.SCHEDULER_NAME);
        if (StringUtils.isNotEmpty(scheduleJob)) {
            ScheduleJob job = FastJsonUtils.jsonToObj(scheduleJob, ScheduleJob.class);
            invoke(job);
        }
    }
}
